<?php


namespace App\Models;

/**
 * 支付回复信息
 * Class PayResponseData
 *
 * @package App\Models
 * @property int $id
 * @property int|null $uniacid
 * @property string $order_id
 * @property string|null $attach
 * @property array $response
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData query()
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData whereAttach($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData whereResponse($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData whereUniacid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PayResponseData whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class PayResponseData extends BaseModel
{
    protected $guarded = [];
    protected $casts = [
        'response' => 'json',
    ];

    /**
     * 记录支付请求日志
     * @param $orderId string 订单id
     * @param string easywechat 方法
     * @param string $attach 附件数据
     * @param array $response 返回参数
     * @return bool
     */
    public static function record($orderId, $attach, $response)
    {
        $data = array(
            'order_id' => (string)$orderId,
            'attach' => (string)$attach,
            'response' => (array)$response,
        );

        $model = new self();

        return $model->fill($data)->save();
    }
}